#ifndef THIS_IS_BOOTLOADER
#include <RA165.h>

RA165::RA165(int clockPin, int dataPin)
{
    m_clockPin = clockPin;
    m_dataPin = dataPin;
    pinMode(m_clockPin, OUTPUT);
    pinMode(m_dataPin, INPUT);
}
uint32_t shiftIn_165(uint32_t ulDataPin, uint32_t ulClockPin, uint32_t ulBitOrder, byte first)
{
    uint8_t value = 0;
    uint8_t i;
    if (first)
    {
        if (ulBitOrder == LSBFIRST)
            value = digitalRead(ulDataPin);
        else
            value = digitalRead(ulDataPin) << 7;
    }
    for (i = first; i < 8; ++i)
    {
        digitalWrite(ulClockPin, HIGH);
        delayMicroseconds(1);
        if (ulBitOrder == LSBFIRST)
        {
            value |= digitalRead(ulDataPin) << i;
        }
        else
        {
            value |= digitalRead(ulDataPin) << (7 - i);
        }

        digitalWrite(ulClockPin, LOW);
        delayMicroseconds(1);
    }

    return value;
}

byte RA165::readByte(RAORDER byteOrder, byte first)
{
    return shiftIn_165(m_dataPin, m_clockPin, byteOrder, first);
}
#endif